import { useState } from 'react';
const NumberGrowth = () => {
  const [con, setCon] = useState(0);
  const userList = [
    { name: '张三', age: '16', address: '广州' },
    { name: '李四', age: '18', address: '上海' },
    { name: '王五', age: '16', address: '北京' },
    { name: '老六', age: '89', address: '广州' }
  ];
  // getUserDetail('name') //返回 {name:['张三','李四','王五','老六'] }
  // getUserDetail('address') //返回 {address:['广州','上海','北京'] }

  //  const getUserDetail=(key)=>{
  //    let target = {}
  //      target[key]=[]
  //      userList.forEach((item)=>{
  //          // eslint-disable-next-line no-unused-expressions, no-undef
  //          target[k]
  //      })
  //    return target
  //  }

  const add = () => {
    new Promise((resolve, reject) => {
      console.log('开始');
      // Promise.resolve(2).then((res)=>{
      //   console.log(res)
      // })
      resolve(1);
      console.log('reslve 后面的输出');
    }).then((re) => {
      console.log(re);
    });
    setCon((pre) => {
      return pre + 1;
    });
  };
  const jian = () => {
    setCon((pre) => {
      return pre - 1;
    });
  };
  return (
    <div
      style={{
        position: 'fixed',
        width: '100vw',
        bottom: 0,
        display: 'flex',
        justifyContent: 'center'
      }}
    >
      <div>{con}</div>
      <button
        onClick={() => {
          add();
        }}
      >
        +
      </button>
      <button
        onClick={() => {
          jian();
        }}
      >
        -
      </button>
    </div>
  );
};

export default NumberGrowth;
